package com.djakapm.markdown.editor.component.action;

import com.djakapm.markdown.editor.AppConstant;
import com.djakapm.markdown.editor.component.EditorComponentPresenter;
import com.djakapm.markdown.editor.util.ResourceManager;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class ViewSourceAction extends AbstractAction {
    private EditorComponentPresenter presenter;

    public ViewSourceAction(EditorComponentPresenter presenter){
        this.presenter = presenter;
        this.putValue(Action.SHORT_DESCRIPTION, AppConstant.VIEW_SOURCE_TOOLTIP_LABEL);
        this.putValue(Action.NAME,AppConstant.VIEW_SOURCE_TOOLTIP_LABEL);
        this.putValue(Action.SMALL_ICON, ResourceManager.getIcon(AppConstant.VIEW_CODE_ICON_NAME));
    }
    
    public void actionPerformed(ActionEvent e) {
        if(this.presenter.isSourceMode()){
            this.presenter.sourceMode();
            this.presenter.setSourceMode(false);
        }
        else{
            this.presenter.renderMode();
            this.presenter.setSourceMode(true);
        }
    }
}
